/*
 * @lc app=leetcode.cn id=1748 lang=typescript
 *
 * [1748] 唯一元素的和
 */

// @lc code=start
function sumOfUnique(nums: number[]): number {
    let cache = new Map<number, boolean>();
    let total = 0;
    for (let i = 0; i < nums.length; i++) {
        const element = nums[i];
        if (cache.has(element)) {
            if (cache.get(element)) {
                continue;
            } else {
                cache.set(element, true);
                total -= element;
            }
        } else {
            cache.set(element, false);
            total += element;
        }
    }
    return total;
}
// @lc code=end
